/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.google.code.restui.core;

import java.net.HttpURLConnection;

/**
 *
 * @author Rohit
 */
public class Authenticator {

    private AuthDetails authDetails;
    private String authType;

    public Authenticator(AuthDetails authDetails, String authType) {
        this.authDetails = authDetails;
        this.authType = authType;
    }

    public void authenticate(HttpURLConnection con){
        if(authType.equalsIgnoreCase("Basic")){
            con.setRequestProperty("Authorization", "Basic " + new sun.misc.BASE64Encoder().encode((authDetails.getUsername() + ":" + authDetails.getPassword()).getBytes()));
        }
    }
}
